﻿using System;
using System.Windows.Input;

namespace Present.Commands.Decorators
{
    /// <summary>
    /// A Decoraotr that passes CanExecutedChange through to CommandManager so CanExecute is reguarlary checkced.
    /// Use if you can tell inside your command whether or not the state you depend on has changed
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class  RequeryCommandDecorator<T> : CommandDecorator<T> where T : ICommand
    {
        public RequeryCommandDecorator(T innerCommand) : base(innerCommand)
        {
        }

        public override event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
    }
}